<?php

namespace openapi\controllers;

/**
 * 例子
 *
 * @author peng.huang
 */
class DemoController extends \openapi\controllers\base\OpenAPIController {

    /**
     * 初始化
     */
    public function init() {
        ENVIRONMENT !== 'dev' AND die('该文件禁止访问');
    }

    /**
     * 默认
     * 
     * @return array
     */
    public function actionIndex() {
        $this->setLayout();
        $api = array_merge(array('All' => ''), include dirname(__DIR__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'ApiFunc.php');
        return array('api' => $api);
    }

    /**
     * 返回验证key
     */
    public function actionValikey() {
        $this->response->setHeaders(array('Content-type' => 'text/json'));
        $arr = array(
            'data' => \common\utils\ApiHelper::getEncryptdStr($this->request->post('key'))
        );

        echo json_encode($arr);
        exit();
    }

    /**
     * 返回功能
     * 
     * @param string $methodType [方法类型]
     */
    public function actionFunc($methodType = NULL) {
        // 对应关系
        $model = array();
        $rels = include dirname(__DIR__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'Relation.php';
        if (isset($rels[$methodType])) {
            $model = new $rels[$methodType]();
        }

        $this->response->setHeaders(array('Content-type' => 'text/json'));
        echo json_encode($model);
        //exit();
    }

}
